﻿using System;
using System.Runtime.InteropServices;

namespace TeamIce
{
	public class Pair<T1, T2>
	{
		public Pair()
		{
		}

		public Pair(T1 first, T2 second)
		{
			First = first;
			Second = second;
		}

		public T1 First { get; set; }
		public T2 Second { get; set; }
	};

	[ComVisible(false)]
    public class Sector : Pair<double, double>
    {
    	public Sector(double aFrom, double aTo)
    	{
    		First = aFrom;
    		Second = aTo;
    	}

    	public double AlphaFrom
    	{
    		get { return First; }
			set { First = value; }
    	}

		public double AlphaTo
		{
			get { return Second; }
			set { Second = value; }
		}

		public double Average
		{
			get { return (First + Second) / 2; }
		}

    	public double Size
    	{
			get { return Math.Abs(Second - First); }
    	}

		public static int CompareBySizeDesc(Sector s1, Sector s2)
		{
			if (s1.Size < s2.Size) return 1;
			if (s1.Size > s2.Size) return -1;
			return 0;
		}

		public bool IsAngleInSector(double angle)
		{
			while (angle < AlphaFrom)
				angle += 2*Math.PI;
			while (angle > AlphaTo)
				angle -= 2 * Math.PI;
			return angle >= AlphaFrom && angle <= AlphaTo;
		}

        public bool IsNotNaN
        {
            get
            {
                return !double.IsNaN(AlphaFrom) && !double.IsNaN(AlphaTo);
            }
        }

		public override string ToString()
		{
			return string.Format("({0:0.00}, {1:0.00})", AlphaFrom, AlphaTo);
		}
    }
}
